package com.xing.controller;

import com.xing.DTO.ArticleDTO;
import com.xing.service.ArticleService;
import com.xing.utils.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Map;

/**
 * @version 1.0
 * @Author Xing
 * @Date 2024/7/16 11:44
 */
@Tag(name = "文章信息")
@RestController
@RequestMapping("posts")
public class ArticleController {
    @Autowired
    private ArticleService service;

    @Operation(summary = "新建文章")
    @PostMapping
    public Result Save(@RequestBody ArticleDTO dto) {
        return service.Save(dto);
    }

    @Operation(summary = "获取某个用户文章列表")
    @GetMapping
    public Result page(@RequestParam Map<String, Object> params) {
        return service.Page(params);
    }

    @Operation(summary = "获取文章详情")
    @GetMapping("{id}")
    public Result Get(@PathVariable("id") Long id) {
        return service.GetArticleById(id);
    }

    @Operation(summary = "更新文章")
    @PutMapping("{id}")
    public Result Put(@PathVariable("id") Long id,@RequestBody ArticleDTO dto){
        return service.PutArticleById(id,dto);
    }

    @Operation(summary = "删除文章")
    @DeleteMapping("{id}")
    public Result Delete(@PathVariable("id") Long id) {
        return service.DeleteArticleById(id);
    }

}
